<template>
  <ga-pagination
    v-model="currentPage"
    :total="total"
    :default-current="currentPage"
    show-total
    size="mini"
    show-jumper
    show-page-size
    :page-size="limit"
    @change="handleCurrentChange"
    @page-size-change="handleSizeChange"
  />
</template>

<script lang="ts" setup>
  import { computed } from 'vue';

  const props = defineProps({
    total: {
      required: true,
      default: 0,
    },
    page: {
      type: Number,
      required: true,
      default: 1,
    },
    limit: {
      required: true,
      default: 10,
    }
  });

  const emit = defineEmits(['update:page', 'update:limit', 'pagination']);
  const currentPage = computed({
    get() {
      return props.page;
    },
    set(val) {
      emit('update:page', val);
    },
  });
  const pageSize = computed({
    get() {
      return props.limit;
    },
    set(val) {
      emit('update:limit', val);
    },
  });
  const handleSizeChange = (val: any) => {
    emit('pagination', { page: currentPage.value, limit: val });
  };
  const handleCurrentChange = (val: any) => {
    emit('pagination', { page: val, limit: pageSize.value });
  };
</script>
